package Java100_1006;

import java.util.Scanner;

//编写系统的主体逻辑
public class Main {
    public static void main(String[] args) {
        //通过login方法进行登录
        User user = login();
        while(true){
            int choice = user.menu();
            user.doOperation(choice);
        }
    }

    private static User login() {
        //1.实现用户登录逻辑
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String userName = scanner.next();
        System.out.println("请输入密码：");
        String passWord = scanner.next();
        //2.从数据库根据用户名查询密码
        UserDao userDao = new UserDao();
        User user = userDao.selectByName(userName);
        if(user == null){
            //不存在该用户
            System.out.println("登陆失败!");
            // 直接退出程序
            System.exit(0);
        }
        if(!user.getPassWord().equals(passWord)){
            //密码不正确
            System.out.println("登陆失败");
            System.exit(0);
        }
        return user;
    }
}
